/*
 * ComboBoxWizard4.java
 *
 * Created on May 26, 2006, 4:38 AM
 */


import java.awt.Component;
import java.awt.PopupMenu;
import java.util.Vector;

/**
 *
 * @author  yaco
 */
public class ComboBoxWizard4 extends javax.swing.JFrame {
 
    Vector<String> tables=new Vector<String>();
    Vector fields=new Vector();
    int size;
    Vector<Object> list1Data=new Vector<Object>();
    static  Vector<Object> list2Data=new Vector<Object>();
    Object[] temp=new Object[0];
    
    /** Creates new form ComboBoxWizard4 */
    public ComboBoxWizard4() {
        initComponents();
        this.setSize(550,350);
        this.setLocation(250,200);

    }
    

    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel6 = new javax.swing.JLabel();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Combo Box Wizard");
        setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("mysql.JPEG")));
        setResizable(false);
        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\yaco\\comboBoxWizard\\src\\Images\\cb5.png"));
        getContentPane().add(jLabel1);
        jLabel1.setBounds(10, 10, 130, 0);

        jLabel2.setText("Which fields contain the values you want included in your combo");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(140, 20, 400, 14);

        jLabel3.setText("box? the fields you select become columns in your combo box.");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(140, 40, 420, 14);

        jLabel4.setText("Available Fields:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(180, 80, 90, 14);

        jScrollPane1.setViewportView(jList1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(140, 100, 150, 130);

        jScrollPane2.setViewportView(jList2);

        getContentPane().add(jScrollPane2);
        jScrollPane2.setBounds(380, 100, 150, 130);

        jButton1.setText(">");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        getContentPane().add(jButton1);
        jButton1.setBounds(310, 110, 50, 23);

        jButton2.setText("<");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        getContentPane().add(jButton2);
        jButton2.setBounds(310, 200, 50, 23);

        jButton3.setText(">>");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        getContentPane().add(jButton3);
        jButton3.setBounds(310, 140, 50, 23);

        jButton4.setText("<<");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        getContentPane().add(jButton4);
        jButton4.setBounds(310, 170, 49, 23);

        jLabel5.setText("Selected Fields:");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(420, 80, 90, 14);

        jButton5.setText("Cancel");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });

        getContentPane().add(jButton5);
        jButton5.setBounds(130, 280, 80, 23);

        jButton6.setText("<  Back");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton6MouseClicked(evt);
            }
        });

        getContentPane().add(jButton6);
        jButton6.setBounds(260, 280, 90, 23);

        jButton7.setText("Next  >");
        jButton7.setEnabled(false);
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton7MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton7MouseEntered(evt);
            }
        });

        getContentPane().add(jButton7);
        jButton7.setBounds(350, 280, 90, 23);

        jButton8.setText("Finish");
        jButton8.setEnabled(false);
        getContentPane().add(jButton8);
        jButton8.setBounds(440, 280, 90, 23);

        getContentPane().add(jSeparator2);
        jSeparator2.setBounds(10, 260, 520, 20);

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/cb5.png")));
        jLabel6.setText("jLabel6");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(10, -20, 110, 180);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton7MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseEntered
// TODO add your handling code here:
    }//GEN-LAST:event_jButton7MouseEntered

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
// TODO add your handling code here:
      list2Data.removeAllElements();
      jList2.setListData(list2Data);
      fields=MainWindow.dbCon.getFields(ComboBoxWizard3.table);
      list1Data=fields;
      jList1.setListData(list1Data);  
      jButton7.setEnabled(false);
    }//GEN-LAST:event_jButton4MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
// TODO add your handling code here:
      list1Data.removeAllElements();
      jList1.setListData(list1Data);
      fields=MainWindow.dbCon.getFields(ComboBoxWizard3.table);
      list2Data=fields;
      jList2.setListData(list2Data);  
      jButton7.setEnabled(true);
    }//GEN-LAST:event_jButton3MouseClicked

    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton6MouseClicked
// TODO add your handling code here:
        this.dispose();
        ComboBoxWizard1.comboBoxWizard3.setVisible(true);
    }//GEN-LAST:event_jButton6MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
// TODO add your handling code here:
     Object []list=jList2.getSelectedValues();
     
     for(int i=0;i<list.length;i++){
         list2Data.remove(list[i]);
         list1Data.add(list[i]);
     }
     
     jList2.setListData(list2Data);
     jList1.setListData(list1Data);
     
     if (list2Data.isEmpty()){
         jButton7.setEnabled(false);
     }
     else{
         jButton7.setEnabled(true);
     }
     
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// TODO add your handling code here:
     Object []list=jList1.getSelectedValues();
     
     for(int i=0;i<list.length;i++){
         list1Data.remove(list[i]);
         list2Data.addElement(list[i]);
     }
     
     jList2.setListData(list2Data);
     jList1.setListData(list1Data);
     
     if (list2Data.isEmpty()){
        jButton7.setEnabled(false);
     }
     else{
          jButton7.setEnabled(true);
     }
          
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseClicked
        
        if (jButton7.isEnabled())    {
            this.setVisible(false);
            ComboBoxWizard1.comboBoxWizard5=new ComboBoxWizard5();
            ComboBoxWizard1.comboBoxWizard5.setVisible(true);         
            ComboBoxWizard1.comboBoxWizard5.init();
        }
// TODO add your handling code here:
    }//GEN-LAST:event_jButton7MouseClicked

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
        
        this.dispose();
// TODO add your handling code here:
    }//GEN-LAST:event_jButton5MouseClicked
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               ComboBoxWizard1.comboBoxWizard6.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    public javax.swing.JList jList1;
    public javax.swing.JList jList2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables
    
}
